package com.api.hg.action;

import com.api.hg.BaseUtle;
import com.api.hg.model.uf_kszcpdrw;
import com.api.sw.duban.util.LogTool;
import com.cloudstore.eccom.constant.WeaBoolAttr;
import com.cloudstore.eccom.pc.table.WeaTable;
import com.cloudstore.eccom.pc.table.WeaTableColumn;
import com.cloudstore.eccom.pc.table.WeaTableType;
import com.cloudstore.eccom.result.WeaResultMsg;
import weaver.conn.RecordSet;
import weaver.general.PageIdConst;
import weaver.general.Util;
import weaver.hrm.User;

import java.util.HashMap;
import java.util.Map;

/**
 * 盘点清单 相关列表
 */
public class discoveryList {
    private final static LogTool log = new LogTool("/log/assetlog/luolf/discoveryList",false);

    /**
     * 通过人员获取盘点任务清单(包括下发任务，部门任务，科室任务 )
     *
     * @param params
     * @param user
     * @return
     */
    public Map<String, Object> getTableDiscovery(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }
        try {
            String ksids=getKsadminByUser(user.getUID());//人员所属科室管理员
            boolean issysadmin=BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"");//是否是  资产管理员
            assetAction assetAction=new assetAction();
            String subid=assetAction.getSubQxByUserNotadmin(user);//人员 所属分布权限
            String year= com.weaver.general.Util.null2String((String)params.get("year"));//年份
            String bt= com.weaver.general.Util.null2String((String)params.get("bt"));//标题
            String type= com.weaver.general.Util.null2String((String)params.get("type"));//查看范围  0：资产管理员  1：部门  2：科室
            //返回消息结构体
            WeaResultMsg result = new WeaResultMsg(false);
            RecordSet re=new RecordSet();
            String DBType=re.getDBType();
            //log.writeLog("DBType"+DBType);
            String pageID = "17ecc14c-9d64-4a43-81a4-7b7c6f79285711111111113";
            String pageUid = pageID + "_" + user.getUID();
            String pageSize = PageIdConst.getPageSize(pageID, user.getUID());
            uf_kszcpdrw uf_kszcpdrw=null;//科室实体类
            String sqlwhere =" 1=1 ";
            if(!"".equals(bt)){
                sqlwhere=sqlwhere+" and a1.rwbt like '%"+bt+"%'";
            }
            if(!"".equals(year)){
                sqlwhere=sqlwhere+" and a1.pdnf = '"+year+"'";
            }
            String adminwhere="";
            if(issysadmin){
                adminwhere=" modedatacreater="+user.getUID()+" ";
            }else{
                adminwhere=" 1=2 ";
            }
            //故意加 一个 1
            String fromSql=" from ( 1 " +
                           " select  'all_'+cast(id as varchar(600)) ids,pdnf,rwbt,xfry,xfrq,pdqx,cast(pdbm as varchar(600)) pdbm,sblx,'0' type from uf_zcpdrwxf where  " +adminwhere+
                           " union all " +
                           " select 'sub_'+cast(a.id as varchar(600)) ids,a.pdnf,b.rwbt,a.pdxfr,a.xfrq,a.pdqx,a.pdbm,b.sblx,'1' type from uf_bmzcpdrw a left join uf_zcpdrwxf b on a.pdrwbt=b.id where a.pdbm in ("+subid+") " +
                           " union all " +
                           " select 'dep_'+cast(a.id as varchar(600)) ids,a.pdnf,b.rwbt,a.pdxfr,a.xfrq,a.pdqx,a.pdks,b.sblx,'2' type from uf_kszcpdrw a left join uf_zcpdrwxf b on a.pdrwbt=b.id where a.pdks in ("+ksids+") " +
                           " ) a1";
            if("0".equals(type)){

                fromSql=" from ( " +
                        " select  'all_'+cast(id as varchar(600)) ids,pdnf,rwbt,xfry,xfrq,pdqx,cast(pdbm as varchar(600)) pdbm,sblx,'0' type from uf_zcpdrwxf where isnull(lypdfs,-1)=0 and  " +adminwhere+
                        " ) a1";
            }
            if("1".equals(type)){
                fromSql=" from ( " +
                        " select 'sub_'+cast(a.id as varchar(600)) ids,a.pdnf,b.rwbt,a.pdxfr,a.xfrq,a.pdqx,a.pdbm,b.sblx,'1' type from uf_bmzcpdrw a left join uf_zcpdrwxf b on a.pdrwbt=b.id where isnull(lypdfs,-1)=1 and a.pdbm in ("+subid+") " +
                        " ) a1";
            }
            if("2".equals(type)){
                fromSql=" from ( " +
                        " select 'dep_'+cast(a.id as varchar(600)) ids,a.pdnf,b.rwbt,a.pdxfr,a.xfrq,a.pdqx,a.pdks,b.sblx,'2' type from uf_kszcpdrw a left join uf_zcpdrwxf b on a.pdrwbt=b.id where isnull(lypdfs,-1)=2 and a.pdks in ("+ksids+") " +
                        " ) a1";
            }
            log.writeLog("type-->"+sqlwhere);

            if("1".equals(user.getUID()+"")){
                //select ids,pdnf,rwbt,xfry,xfrq,pdqx, pdbm,sblx, type
                 fromSql="  from ( " +
                        " select  'all_'+cast(id as varchar(600)) ids,pdnf,rwbt,xfry,xfrq,pdqx,cast(pdbm as varchar(600)) pdbm,sblx,'0' type from uf_zcpdrwxf " +
                        " union all " +
                        " select  'sub_'+cast(a.id as varchar(600)) ids,a.pdnf,b.rwbt,a.pdxfr,a.xfrq,a.pdqx,a.pdbm,b.sblx,'1' type from uf_bmzcpdrw a left join uf_zcpdrwxf b on a.pdrwbt=b.id " +
                        " union all " +
                        " select  'dep_'+cast(a.id as varchar(600)) ids,a.pdnf,b.rwbt,a.pdxfr,a.xfrq,a.pdqx,a.pdks,b.sblx,'2' type from uf_kszcpdrw a left join uf_zcpdrwxf b on a.pdrwbt=b.id " +
                        " ) a1";
            }

            //销账页面的数据得过滤下，系统管理员显示全部，部门管理员只显示本部门的（中山海关和缉私局的显示到下级分部）
            //(BaseUtle.ckeckRole(userid+"",BaseUtle.subsysadmin+","+BaseUtle.zssysadmin+","+BaseUtle.sysadmin)

//            DoorUtil DoorUtil=new DoorUtil();
//            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")||"1".equals((user.getUID()+""))){//管理员
//                sqlwhere=sqlwhere+" and 1=1";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+","+DoorAaction.jsjsub)){//中山 缉私局
//                sqlwhere=sqlwhere+" and sybm in ("+DoorUtil.getAllSub(user.getUserSubCompany1()+"")+")";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.subsysadmin+"")){
//                sqlwhere=sqlwhere+" and sybm in ("+user.getUserSubCompany1()+")";
//            }else{
//                sqlwhere=sqlwhere+" and 1!=1";
//            }

            log.writeLog(sqlwhere);
            //新建一个weatable
            WeaTable table = new WeaTable();
            table.setTableType(WeaTableType.CHECKBOX);
            table.setPageUID(pageUid);
            table.setPageID(pageID);
            table.setPagesize(pageSize);

            String backfields =	" ids,pdnf,rwbt,xfry,xfrq,pdqx, pdbm,sblx, type ";
            //String fromSql=" from (select a.gbzcid,a.kph, a.gdzcbm, a.gdzcmc,a.ggxh,a.pp,a.dj,b.lastname syrlastname,a.bz,c.sybm2,c.dwmc,a.mldm,a.sybm from uf_uf_gbxtzczmxxexc a left join  hrmresource b on a.syr=b.id left join uf_gbxtzczmxx c on a.gbzcid=c.id where len(isnull(a.kpwybs,'')+isnull(a.kph,''))>0  and isnull(a.sfyxz,-1) in (-1,1)   ) a "	;
            //String fromSql=" from (select   a.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id where len(isnull(a.xzgbxtzc,''))<=0  and  "+sqlwhere+" ) a1 "	;

            log.writeLog(fromSql);
            table.setBackfields(backfields);

            table.setSqlform(fromSql);
            table.setSqlwhere(sqlwhere);
            //table.setSqlorderby("gbzcid");
            //table.setSqlprimarykey("gbzcid");
            //kpwybs
            table.setSqlorderby("ids");//swzc
            table.setSqlprimarykey("ids");
            table.setSqlisdistinct("false");
            //卡片号，目录代码，固定资产名称，品牌，规格型号，所在部门2(表里有两个所在部门，取带有数字2的那个)，对应单位，关联实物资产(这个放后面)
            table.getColumns().add(new WeaTableColumn("ids").setDisplay(WeaBoolAttr.FALSE));   //设置为不显示
            table.getColumns().add(new WeaTableColumn("type").setDisplay(WeaBoolAttr.FALSE));   //设置为不显示
            //table.getColumns().add(new WeaTableColumn("10%", "实物资产编号", "swzcspan","swzcspan","com.api.hg.util.TranceUtil.getSwTitle").setOtherpara("column:id"));
            table.getColumns().add(new WeaTableColumn("10%", "任务标题", "rwbt","rwbt"));
            table.getColumns().add(new WeaTableColumn("10%", "盘点年份", "pdnf","pdnf"));
            table.getColumns().add(new WeaTableColumn("10%", "盘点下发人", "xfry","xfry","com.api.hg.util.DisTranceUtil.getHrmLastname"));
            table.getColumns().add(new WeaTableColumn("10%", "盘点期限", "pdqx","pdqx"));
            table.getColumns().add(new WeaTableColumn("10%", "设备类型", "sblx","sblx","com.api.hg.util.DisTranceUtil.getSblxDesc"));
            table.getColumns().add(new WeaTableColumn("10%", "盘点部门/科室", "pdbm","pdbm","com.api.hg.util.DisTranceUtil.getSubOrDep").setOtherpara("column:type"));
            table.getColumns().add(new WeaTableColumn("10%", "下发日期", "xfrq","xfrq"));
            table.getColumns().add(new WeaTableColumn("10%", "待盘点资产数量", "wating","ids","com.api.hg.util.DisTranceUtil.waitingDiscoveryCount").setOtherpara("column:ids"));
            table.getColumns().add(new WeaTableColumn("10%", "已盘点资产数量", "ypd","ids","com.api.hg.util.DisTranceUtil.DiscoveryCount").setOtherpara("column:ids"));
            table.getColumns().add(new WeaTableColumn("10%", "操作", "opter","opter"));



            //增加右侧操作选项
            //weaTableOperates.setOperate(operateList);

            //table.setOperates(weaTableOperates);
            //table.setOperates(weaTableOperates);

            result.putAll(table.makeDataResult());
            result.put("hasRight", true);
            result.success();
            apidatas = result.getResultMap();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return apidatas;
    }

    /**
     * 获取人员对应的 科室
     * @param userid
     * @return
     */
    public String getKsadminByUser(int userid){
        String ks="";
        String sql="select deptid from HrmDepartmentDefined where ','+cast(swzcgly as varchar(600))+',' like '%,"+userid+",%' ";
        RecordSet re=new RecordSet();
        re.execute(sql);
        while(re.next()){
            String depid= Util.null2String(re.getString("deptid")).trim();
            if(!"".equals(depid)){
                ks=ks+depid+",";
            }
        }
        if(ks.endsWith(",")){
            ks=ks.substring(0,ks.length()-1);
        }
        return ks;
    }
    /**
     * 校验是或否是资产管理员
     *
     * @param params
     * @param user
     * @return
     */
    public Map<String, Object> CheckAssAdmin(Map<String,Object> params, User user) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        if (null == user) {
            apidatas.put("hasRight", false);
            apidatas.put("api_status",false);
            return apidatas;
        }
        boolean flag=BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")?true:("1".equals((user.getUID()+"")));
        apidatas.put("api_status",flag);
        return apidatas;
    }

    //盘点任务资产清单
    //实物的：hth 合同号，pp 品牌(浏览单选)，ggxh规格型号(浏览单选)，sblx设备类型(浏览单选)，sbzt设备状态(公共选择框)
    public Map<String, Object> getTableDataSW(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }
        try {
            String pp=(String)Util.null2String(params.get("pp")) ;//品牌
            String ggxh=(String)Util.null2String(params.get("ggxh")) ;//规格型号
            String sblx=(String)Util.null2String(params.get("sblx")) ;//设备类型
            String sbzt=(String)Util.null2String(params.get("sbzt")) ;//设备状态
            String rq=(String)Util.null2String(params.get("rq")) ;//入库日期
            String type=(String)Util.null2String(params.get("type")) ;//查询类型 0：资产管理员下发的 1：部门管理员下发的  2：科室下发的
            String Singlehrm=(String)Util.null2String(params.get("singlehrm")) ;//个人盘点查询
            String rwid=(String)Util.null2String(params.get("rwid")) ;//任务ID
            String pdzt=(String)Util.null2String(params.get("pdzt")) ;//盘点状态
            //返回消息结构体
            WeaResultMsg result = new WeaResultMsg(false);
            RecordSet re=new RecordSet();
            String DBType=re.getDBType();
            //log.writeLog("DBType"+DBType);
            String pageID = "17ecc14c-9d64-4a43-81a4-7b7c6f792857111111111";
            String pageUid = pageID + "_" + user.getUID();
            String pageSize = PageIdConst.getPageSize(pageID, user.getUID());

            String sqlwhere =" 1=1 ";
            if(!"".equals(pp)){
                if(pp.endsWith(",")){
                    pp=pp.substring(0,pp.length()-1);
                }
                sqlwhere=sqlwhere+" and a.pp in ("+pp+")";
            }
            if(!"".equals(ggxh)){
                if(ggxh.endsWith(",")){
                    ggxh=ggxh.substring(0,ggxh.length()-1);
                }
                sqlwhere=sqlwhere+" and a.ggxh in ("+ggxh+")";
            }
            if(!"".equals(sblx)){
                if(sblx.endsWith(",")){
                    sblx=sblx.substring(0,sblx.length()-1);
                }
                sqlwhere=sqlwhere+" and a.zclx in ("+sblx+")";
            }
            if(!"".equals(sbzt)){
                sqlwhere=sqlwhere+" and a.zczt='"+sbzt+"'";
            }
            if(!"".equals(rq)){
                sqlwhere=sqlwhere+" and a.rkrq='"+rq+"'";
            }
            if(!"".equals(pdzt)){
                sqlwhere=sqlwhere+" and f.pdzt='"+pdzt+"'";
            }
            //销账页面的数据得过滤下，系统管理员显示全部，部门管理员只显示本部门的（中山海关和缉私局的显示到下级分部）
            //(BaseUtle.ckeckRole(userid+"",BaseUtle.subsysadmin+","+BaseUtle.zssysadmin+","+BaseUtle.sysadmin)

//            DoorUtil DoorUtil=new DoorUtil();
//            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")||"1".equals((user.getUID()+""))){//管理员
//                sqlwhere=sqlwhere+" and 1=1";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+","+DoorAaction.jsjsub)){//中山 缉私局
//                sqlwhere=sqlwhere+" and sybm in ("+DoorUtil.getAllSub(user.getUserSubCompany1()+"")+")";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.subsysadmin+"")){
//                sqlwhere=sqlwhere+" and sybm in ("+user.getUserSubCompany1()+")";
//            }else{
//                sqlwhere=sqlwhere+" and 1!=1";
//            }

            log.writeLog(sqlwhere);
            //新建一个weatable
            WeaTable table = new WeaTable();
            table.setTableType(WeaTableType.CHECKBOX);
            table.setPageUID(pageUid);
            table.setPageID(pageID);
            table.setPagesize(pageSize);

            String backfields =	" id,ggxh,pp,zczt,swzcspan,swzc,zclx,zclxmc,swpp,swggxh,rkrq,pdzt,'uf_grzcpdjl' tablename,'pdzt' ztfield";
            //len(isnull(a.xzgbxtzc,''))<=0 and
            //String fromSql=" from (select a.gbzcid,a.kph, a.gdzcbm, a.gdzcmc,a.ggxh,a.pp,a.dj,b.lastname syrlastname,a.bz,c.sybm2,c.dwmc,a.mldm,a.sybm from uf_uf_gbxtzczmxxexc a left join  hrmresource b on a.syr=b.id left join uf_gbxtzczmxx c on a.gbzcid=c.id where len(isnull(a.kpwybs,'')+isnull(a.kph,''))>0  and isnull(a.sfyxz,-1) in (-1,1)   ) a "	;
            String fromSql=" from (select   f.pdzt,a.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id,uf_grzcpdjl f where  f.swzcid=a.id and F.szglypdrw=-1 and  "+sqlwhere+" ) a1 "	;
            if("0".equals(type)){
                fromSql=" from (select   f.pdzt,a.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id,uf_grzcpdjl f where  f.swzcid=a.id and f.szglypdrw="+rwid+" and isnull(f.sfyx,-1) in (0,-1) and  "+sqlwhere+" ) a1 "	;
            }else if("1".equals(type)){
                fromSql=" from (select   f.pdzt,a.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id,uf_grzcpdjl f where  f.swzcid=a.id and f.szbmpdrw="+rwid+" and isnull(f.sfyx,-1) in (0,-1) and  "+sqlwhere+" ) a1 "	;
            }else if("2".equals(type)){
                fromSql=" from (select   f.pdzt,a.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id,uf_grzcpdjl f where  f.swzcid=a.id and f.szkspdrw="+rwid+" and isnull(f.sfyx,-1) in (0,-1) and  "+sqlwhere+" ) a1 "	;
            }

            if("0".equals(Singlehrm)){//个人盘点查询
                fromSql=" from (select   f.pdzt,a.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id,uf_grzcpdjl f where  f.swzcid=a.id and f.szglypdrw="+rwid+" and isnull(f.sfyx,-1) in (0,-1) and f.sjzrr='"+user.getUID()+"' and  "+sqlwhere+" ) a1 "	;
            }
            log.writeLog(fromSql);
            table.setBackfields(backfields);

            table.setSqlform(fromSql);
            //table.setSqlwhere(sqlwhere);
            //table.setSqlorderby("gbzcid");
            //table.setSqlprimarykey("gbzcid");
            //kpwybs
            table.setSqlorderby("id");//swzc
            table.setSqlprimarykey("id");
            table.setSqlisdistinct("false");
            //卡片号，目录代码，固定资产名称，品牌，规格型号，所在部门2(表里有两个所在部门，取带有数字2的那个)，对应单位，关联实物资产(这个放后面)
            table.getColumns().add(new WeaTableColumn("id").setDisplay(WeaBoolAttr.FALSE));   //设置为不显示
            table.getColumns().add(new WeaTableColumn("10%", "实物资产编号", "swzcspan","swzcspan","com.api.hg.util.TranceUtil.getSwTitle").setOtherpara("column:id"));
            table.getColumns().add(new WeaTableColumn("10%", "设备类型", "zclxmc","zclxmc"));
            table.getColumns().add(new WeaTableColumn("10%", "品牌", "swpp","swpp"));
            table.getColumns().add(new WeaTableColumn("10%", "规格型号", "swggxh","swggxh"));
            table.getColumns().add(new WeaTableColumn("10%", "入库日期", "rkrq","rkrq"));
            //table.getColumns().add(new WeaTableColumn("10%", "盘点状态", "pdzt","pdzt"));
            WeaTableColumn zt=new WeaTableColumn("10%", "盘点状态", "pdzt","pdzt","com.api.hg.util.DisTranceUtil.getSelectnameByValue");
            zt.setOtherpara("column:tablename").setOtherpara2("column:ztfield");
            table.getColumns().add(zt);

            //增加右侧操作选项
            //weaTableOperates.setOperate(operateList);

            //table.setOperates(weaTableOperates);
            //table.setOperates(weaTableOperates);

            result.putAll(table.makeDataResult());
            result.put("hasRight", true);
            result.success();
            apidatas = result.getResultMap();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return apidatas;
    }

    /**
     * 通过人员获取盘点任务清单(包括下发任务，部门任务，科室任务 )
     *
     * @param params
     * @param user
     * @return
     */
    public Map<String, Object> getSinglediscoveryswtable(Map<String,Object> params, User user){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }
        try {
            String ksids=getKsadminByUser(user.getUID());//人员所属科室管理员
            boolean issysadmin=BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"");//是否是  资产管理员
            assetAction assetAction=new assetAction();
            String subid=assetAction.getSubQxByUserNotadmin(user);//人员 所属分布权限
            String year= com.weaver.general.Util.null2String((String)params.get("year"));//年份
            String bt= com.weaver.general.Util.null2String((String)params.get("bt"));//标题
            String type= com.weaver.general.Util.null2String((String)params.get("type"));//查看范围  0：资产管理员  1：部门  2：科室
            //返回消息结构体
            WeaResultMsg result = new WeaResultMsg(false);
            RecordSet re=new RecordSet();
            String DBType=re.getDBType();
            //log.writeLog("DBType"+DBType);
            String pageID = "17ecc14c-9d64-4a43-81a4-7b7c16f79285711111111113";
            String pageUid = pageID + "_" + user.getUID();
            String pageSize = PageIdConst.getPageSize(pageID, user.getUID());
            uf_kszcpdrw uf_kszcpdrw=null;//科室实体类
            String sqlwhere =" 1=1 ";
            if(!"".equals(bt)){
                sqlwhere=sqlwhere+" and a1.rwbt like '%"+bt+"%'";
            }
            if(!"".equals(year)){
                sqlwhere=sqlwhere+" and a1.pdnf = '"+year+"'";
            }
            String adminwhere="";
            //故意加 一个 1
            String fromSql="";

            fromSql=" from ( " +
                        " select distinct b.id ids,b.pdnf,b.rwbt,b.xfry pdxfr,b.xfrq,b.pdqx,b.sblx,'2' type from  uf_zcpdrwxf b  where b.id in (select a.szglypdrw from uf_grzcpdjl a where isnull(a.sfyx,-1) in(0,-1) and isnull(a.sfkspd,-1) in (0) and ( a.sjzrr='"+user.getUID()+"')) " +//','+cast(a.pdzrr as varchar(100))+',' like '%%' or
                        " ) a1";

            log.writeLog("type-->"+sqlwhere);

            if("1".equals(user.getUID()+"")){
                //select ids,pdnf,rwbt,xfry,xfrq,pdqx, pdbm,sblx, type
                fromSql="  from ( " +
                        " select  'all_'+cast(id as varchar(600)) ids,pdnf,rwbt,xfry,xfrq,pdqx,cast(pdbm as varchar(600)) pdbm,sblx,'0' type from uf_zcpdrwxf " +
                       " ) a1";
            }

            //销账页面的数据得过滤下，系统管理员显示全部，部门管理员只显示本部门的（中山海关和缉私局的显示到下级分部）
            //(BaseUtle.ckeckRole(userid+"",BaseUtle.subsysadmin+","+BaseUtle.zssysadmin+","+BaseUtle.sysadmin)

//            DoorUtil DoorUtil=new DoorUtil();
//            if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.sysadmin+"")||"1".equals((user.getUID()+""))){//管理员
//                sqlwhere=sqlwhere+" and 1=1";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.zssysadmin+","+DoorAaction.jsjsub)){//中山 缉私局
//                sqlwhere=sqlwhere+" and sybm in ("+DoorUtil.getAllSub(user.getUserSubCompany1()+"")+")";
//            }else if(BaseUtle.ckeckRole(user.getUID()+"",BaseUtle.subsysadmin+"")){
//                sqlwhere=sqlwhere+" and sybm in ("+user.getUserSubCompany1()+")";
//            }else{
//                sqlwhere=sqlwhere+" and 1!=1";
//            }

            log.writeLog("getSinglediscoveryswtable-->"+fromSql);
            //新建一个weatable
            WeaTable table = new WeaTable();
            table.setTableType(WeaTableType.CHECKBOX);
            table.setPageUID(pageUid);
            table.setPageID(pageID);
            table.setPagesize(pageSize);

            String backfields =	" ids,pdnf,rwbt,xfry,xfrq,pdqx,sblx, type ";
            //String fromSql=" from (select a.gbzcid,a.kph, a.gdzcbm, a.gdzcmc,a.ggxh,a.pp,a.dj,b.lastname syrlastname,a.bz,c.sybm2,c.dwmc,a.mldm,a.sybm from uf_uf_gbxtzczmxxexc a left join  hrmresource b on a.syr=b.id left join uf_gbxtzczmxx c on a.gbzcid=c.id where len(isnull(a.kpwybs,'')+isnull(a.kph,''))>0  and isnull(a.sfyxz,-1) in (-1,1)   ) a "	;
            //String fromSql=" from (select   a.id,a.dybm,a.zczt,a.zclx,a.ggxh,a.pp,a.kpwybh swzc,a.swzcbh swzcspan,b.flmc zclxmc,d.ppmc swpp,c.ggxh swggxh,a.rkrq from uf_swzczmxx a left join uf_sbflxx b on a.zclx=b.id left join uf_swzcggxh c on a.ggxh=c.id left join uf_swzcpp d on a.pp=d.id where len(isnull(a.xzgbxtzc,''))<=0  and  "+sqlwhere+" ) a1 "	;

            log.writeLog(fromSql);
            table.setBackfields(backfields);

            table.setSqlform(fromSql);
            table.setSqlwhere(sqlwhere);
            //table.setSqlorderby("gbzcid");
            //table.setSqlprimarykey("gbzcid");
            //kpwybs
            table.setSqlorderby("ids");//swzc
            table.setSqlprimarykey("ids");
            table.setSqlisdistinct("false");
            //卡片号，目录代码，固定资产名称，品牌，规格型号，所在部门2(表里有两个所在部门，取带有数字2的那个)，对应单位，关联实物资产(这个放后面)
            table.getColumns().add(new WeaTableColumn("ids").setDisplay(WeaBoolAttr.FALSE));   //设置为不显示
            table.getColumns().add(new WeaTableColumn("type").setDisplay(WeaBoolAttr.FALSE));   //设置为不显示
            //table.getColumns().add(new WeaTableColumn("10%", "实物资产编号", "swzcspan","swzcspan","com.api.hg.util.TranceUtil.getSwTitle").setOtherpara("column:id"));
            table.getColumns().add(new WeaTableColumn("10%", "任务标题", "rwbt","rwbt"));
            table.getColumns().add(new WeaTableColumn("10%", "盘点年份", "pdnf","pdnf"));
            table.getColumns().add(new WeaTableColumn("10%", "盘点下发人", "xfry","xfry","com.api.hg.util.DisTranceUtil.getHrmLastname"));
            table.getColumns().add(new WeaTableColumn("10%", "盘点期限", "pdqx","pdqx"));
            table.getColumns().add(new WeaTableColumn("10%", "设备类型", "sblx","sblx","com.api.hg.util.DisTranceUtil.getSblxDesc"));
            table.getColumns().add(new WeaTableColumn("10%", "下发日期", "xfrq","xfrq"));
            table.getColumns().add(new WeaTableColumn("10%", "待盘点资产数量", "wating","ids","com.api.hg.util.DisTranceUtil.waitingDiscoveryCount").setOtherpara("column:ids"));
            table.getColumns().add(new WeaTableColumn("10%", "已盘点资产数量", "ypd","ids","com.api.hg.util.DisTranceUtil.DiscoveryCount").setOtherpara("column:ids"));
            table.getColumns().add(new WeaTableColumn("10%", "操作", "opter","opter"));


            //增加右侧操作选项
            //weaTableOperates.setOperate(operateList);

            //table.setOperates(weaTableOperates);
            //table.setOperates(weaTableOperates);

            result.putAll(table.makeDataResult());
            result.put("hasRight", true);
            result.success();
            apidatas = result.getResultMap();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return apidatas;
    }
}
